#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
应用程序框架分析器 - 图形界面入口
支持拖拽分析应用程序包
"""

import sys
import logging
from pathlib import Path

# 设置日志
logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
    handlers=[
        logging.FileHandler("app_analyzer.log", mode='a'),
        logging.StreamHandler()
    ]
)
logger = logging.getLogger("FrameworkAnalyzerGUI")

def main():
    """程序入口点"""
    try:
        # 导入GUI模块
        from src.gui.utils import init_drag_and_drop
        from src.gui.main_window import FrameworkAnalyzerGUI
        
        # 初始化拖放支持并创建主窗口
        root = init_drag_and_drop()
        
        # 创建应用程序实例
        app = FrameworkAnalyzerGUI(root)
        
        # 设置应用图标
        try:
            icon_path = Path("resources/app_icon.ico")
            if icon_path.exists():
                root.iconbitmap(str(icon_path))
            else:
                logger.warning(f"图标文件不存在: {icon_path}")
        except Exception as e:
            logger.warning(f"设置图标失败: {e}")
        
        # 启动主循环
        root.mainloop()
        
    except ImportError as e:
        logger.error(f"导入模块失败: {e}")
        print(f"错误: 无法导入必要的模块: {e}")
        print("请确保已安装所有依赖项: pip install -r requirements.txt")
        sys.exit(1)
    except Exception as e:
        logger.error(f"启动GUI失败: {e}")
        import traceback
        logger.error(traceback.format_exc())
        print(f"错误: {e}")
        sys.exit(1)

if __name__ == "__main__":
    main() 